/**
 * Course			:	ISYS2119 - BIS Development 2
 * Assignment		:	02
 * Date due			:	01/08/2012
 * Program 			:	Saigon Bike Rental Catalogue System
 * 
 * Programmer		:	Vuu Ngoc My Linh, Tran Thi Van Anh
 * StudentID     	:	s3342015, s3342025
 * Attributions		:	Lecture slides, Blackboard, Tutorials, Websites
 * ====================================================================
 * Description: A class contain and manipulate Bike objects 						
 */

package rmit.ISYS2119.assign02;

import java.util.*;

public class BikeCatalogue {

	// Declare variables
	private ArrayList<Bike> bikes;
	private BikeDataReader dataReader;
	private String bikeFileName;

	/**
	 * @param bikeFileName
	 */
	public BikeCatalogue(String bikeFileName) {

		try {
			bikes = new ArrayList<Bike>();
			dataReader = new BikeDataReader(bikeFileName);
			setBikeFileName(bikeFileName);
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}
	}

	/**
	 * @return the bikes
	 */
	public ArrayList<Bike> getBikes() {
		return bikes;
	}

	/**
	 * @param bikes
	 *            the bikes to set
	 */
	public void setBikes(ArrayList<Bike> bikes) {
		this.bikes = bikes;
	}

	/**
	 * @return the dataReader
	 */
	public BikeDataReader getDataReader() {
		return dataReader;
	}

	/**
	 * @param dataReader
	 *            the dataReader to set
	 */
	public void setDataReader(BikeDataReader dataReader) {
		this.dataReader = dataReader;
	}

	/**
	 * @return the bikeFileName
	 */
	public String getBikeFileName() {
		return bikeFileName;
	}

	/**
	 * @param bikeFileName
	 *            the bikeFileName to set
	 */
	public void setBikeFileName(String bikeFileName) {
		this.bikeFileName = bikeFileName;
	}

	public void addBike(Bike bike) throws Exception {
		bikes.add(bike);
	}

	public Bike getBike(int index) {
		return bikes.get(index);
	}

	// Delete bike
	public boolean deleteBike(Bike bike) {

		boolean deleted = false;

		for (int i = 0; i < bikes.size(); i++) {
			if (bikes.equals(bikes.get(i))) {
				bikes.remove(i);
				deleted = true;
				break;
			}
		}
		return deleted;
	}

	
	public Bike searchByBikeID(int BikeId) {

		Bike bike = null;

		for (int i = 0; i < bikes.size(); i++) {
			if (BikeId == bikes.get(i).getBikeId()) {
				bike = bikes.get(i);
				break;
			}
		}

		return bike;

	}

	public int size() {
		return bikes.size();
	}

	/**
	 * Test BikeCatalogue Class
	 */
	public static void main(String[] args) {
		// Test BikeCatalogue Class
		System.out.println("BikeCatalogue Class is OK");
	}

}
